package com.dycong.common.leetcode.yi;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-09-09
 * Time: 19:41
 */
public class IncreasingTriplet {

    public static void main(String[] args) {
        System.out.println(increasingTriplet(new int[]{1, 7, 6, 8}));
    }

//    public static boolean increasingTriplet(int[] nums) {
//        if(nums.length<3) return false;
//        int diff=1;
//        for(int i=0;i<nums.length-2;i++){
//
//            int left=nums[i];
//            int right=nums[i+1];
//            if(left<=right ){
//                diff+=1;
//            }else if(diff<3){
//                diff=1;
//            }
//
//        }
//        if(nums[nums.length-1]>nums[nums.length-2]){
//            diff+=1;
//        }
//
//        return diff>=3;
//    }

    public static boolean increasingTriplet(int[] nums) {
        int one = Integer.MAX_VALUE;
        int two = Integer.MAX_VALUE;

        for (int n : nums) {
            System.out.println(n);
            if (n <= one) {
                one = n;
            } else if (n <= two) {
                two = n;
            } else {
                return true;
            }
        }

        return false;
    }


}
